<?php View::render('admin/layouts/meta');?>
<link rel="stylesheet" type="text/css" href="<?php echo Router::getBaseUrl(); ?>/lib/fancybox/jquery.fancybox.css" />
<body>
<nav class="breadcrumb">
    <i class="Hui-iconfont">&#xe67f;</i> 首页
    <span class="c-gray en">&gt;</span> 动态文章管理
    <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" >
        <i class="Hui-iconfont">&#xe68f;</i>
    </a>
</nav>
<div class="page-container">
    <form>
        <div class="text-c">
            <span class="select-box" style="width:120px">
                <select class="select" name="isRecommend">
                    <option value="-1">--是否推荐--</option>
                    <option value="0" <?php echo $isRecommend == 0 ? 'selected="selected"' : ''; ?>>
                        否
                    </option>
                    <option value="1" <?php echo $isRecommend == 1 ? 'selected="selected"' : ''; ?>>
                        是
                    </option>
                </select>
            </span>
            <input type="text" class="input-text" style="width:200px" placeholder="用户UID" name="uid" value="<?php echo $uid ? $uid : ''; ?>">
            <input type="text" class="input-text" style="width:200px" placeholder="动态文章标题" name="title" value="<?php echo $title; ?>">
            <input type="hidden" name="page" value="1"/>
            <input type="hidden" name="uid" value="<?php echo $uid; ?>"/>
            <button type="submit" class="btn btn-success radius" id="" name=""><i class="Hui-iconfont">&#xe665;</i> 搜索</button>
        </div>
    </form>
	<div class="cl pd-5 bg-1 bk-gray mt-20">
        <span class="l">

        </span>
        <span class="r">共有数据：<strong><?php echo $total; ?></strong> 条</span>
    </div>
	<div class="mt-20">
	<table class="table table-border table-bordered table-hover table-bg table-sort">
		<thead>
			<tr class="text-c">
				<th width="50">ID</th>
               <!--  <th width="100">类别</th> -->
                <th width="120">标题</th>
                <th width="120">封面图片</th>
                <th width="60">类型</th>
                <th>内容</th>

				<th width="120">添加时间</th>
                <th width="120">更新时间</th>
                <th width="60">状态</th>
                <th width="60">推荐</th>
				<th width="200">操作</th>
			</tr>
		</thead>
		<tbody>
            <?php if ($list) {
	foreach ($list as $info) {
		?>
			<tr class="text-c">
				<td><?php echo $info['dynamic_id']; ?></td>
               <!--  <td><?php echo isset($categoryList[$info['category_id']]) ? $categoryList[$info['category_id']]['name'] : ''; ?></td> -->
                <td class="text-l"><?php echo $info['title']; ?></td>
                <td><img src="<?php echo $info['image']; ?>" style="width:60px;height:60px"/></td>
                <td><?php echo $info['type'] == 1 ? '图文' : '视频'; ?></td>
                <td>
                    <?php if ($info['video_url']) {?>
                    <a href="javascript:;" class="j_video" rel="<?php echo $info['video_url'] ?>">点击播放</a>
                    <?php } else {
			if ($info['image_list']) {
				$imageList = explode('$$$', $info['image_list']);
				foreach ($imageList as $image) {?>
                   <a class="fancybox" href="<?php echo $image ?>" rel="">
                       <img src="<?php echo $image ?>" alt="image" style="width:60px;height:60px;margin-right: 5px" />
                   </a>
                    <?php }}}?>
                </td>
				<td><?php echo $info['add_time']; ?></td>
                <td><?php echo $info['update_time']; ?></td>
                <td>
                    <select class="select" size="1" name="status" id="status" onchange="updatestatus(<?php echo $info['dynamic_id']; ?>,this.value)">
                        <option value="0" <?php echo $info['status'] == 0 ? 'selected="selected"' : ''; ?> >未审核</option>
                        <option value="1" <?php echo $info['status'] == 1 ? 'selected="selected"' : ''; ?> >通过</option>
                        <option value="2" <?php echo $info['status'] == 2 ? 'selected="selected"' : ''; ?> >不通过</option>
                    </select>
                </td>
                <td><?php echo $info['is_recommend'] ?
		'是 <a href="javascript:;" class="j_cal c-red" rel="' . $info['dynamic_id'] . '">[取消]</a>' :
		'否 <a href="javascript:;" class="j_rec c-green" rel="' . $info['dynamic_id'] . '">[推荐]</a>'; ?></td>
				<td class="td-manage">
                    <a href="javascript:;" style="text-decoration:none"  onclick="formAlert('查看详情','<?php echo Router::getBaseUrl(); ?>/admin_dynamic/info?dynamicId=<?php echo $info['dynamic_id']; ?>', '100%','100%')" class="">查看</a>
                    <a href="javascript:;" style="text-decoration:none"  onclick="formAlert('','<?php echo Router::getBaseUrl(); ?>/admin_comment/list?typeId=<?php echo $info['dynamic_id']; ?>', '100%','100%')" class="">评论</a>
                    <a href="javascript:;" style="text-decoration:none"  onclick="formAlert('编辑动态','<?php echo Router::getBaseUrl(); ?>/admin_dynamic/adddaka?dynamicId=<?php echo $info['dynamic_id']; ?>', '100%','100%')" class="">编辑</a>
                    <a href="javascript:;" style="text-decoration:none"  class="j_del ml-5" rel="<?php echo $info['dynamic_id']; ?>">删除</a>
                </td>
			</tr>
            <?php }}?>
		</tbody>
	</table>
        <div>
            <?php echo $pageHtml; ?>
        </div>
	</div>
</div>
</body>
<?php View::render('admin/layouts/footer');?>
<script type="text/javascript" src="<?php echo Router::getBaseUrl(); ?>/lib/fancybox/jquery.fancybox.js"></script>
<script type="text/javascript">
$(function(){
    $('.j_video').click(function(){
        var video =$(this).attr('rel');
       layer.open({
        type: 2,
        title: false,
        area: ['800px', '600px'],
        shade: 0.8,
        closeBtn: 0,
        shadeClose: true,
        content: video
      });
    });
    $(".fancybox").fancybox({openEffect: "none", closeEffect: "none"});

    $('.j_cal').click(function(){
        var id = $(this).attr('rel');
        $.post('<?php echo Router::getBaseUrl(); ?>/admin_dynamic/recommend', {dynamicId:id,status:0}, function (result) {
                if (result.status == 200) {
                    window.location.href = location.href;
                        return true;
                }else{
                    layer.msg(result.msg, {
                        icon: 0,
                        skin: 'u-msg',
                        time: 2200,
                    });
                }
            }, 'json');
        return;
    });

    $('.j_rec').click(function(){
        var id = $(this).attr('rel');
        $.post('<?php echo Router::getBaseUrl(); ?>/admin_dynamic/recommend', {dynamicId:id,status:1}, function (result) {
                if (result.status == 200) {
                    window.location.href = location.href;
                    return true;
                }else{
                    layer.msg(result.msg, {
                        icon: 0,
                        skin: 'u-msg',
                        time: 2200,
                    });
                }
            }, 'json');
        return;
    });

    window.formAlert = function(title, url, w, h) {
        layer.open({
            type: 2,
            title: title,
            area: [w, h],
            content: url,
            end: function(){
               window.location.href=location.href;
            }
          });
    }
    $('.j_del').click(function(){
        var id = $(this).attr('rel');
        $.post('<?php echo Router::getBaseUrl(); ?>/admin_dynamic/delete', {dynamicId:id}, function (result) {
                if (result.status == 200) {
                    layer.msg(result.msg, {
                        icon: 1,
                        skin: 'u-msg',
                        time: 1800,
                    },function() {
                        window.location.href = location.href;
                        return true;
                    });
                }else{
                    layer.msg(result.msg, {
                        icon: 0,
                        skin: 'u-msg',
                        time: 2200,
                    });
                }
            }, 'json');
        return;
    });


});
function updatestatus(dynamicId,status){
        $.post('<?php echo Router::getBaseUrl(); ?>/admin_dynamic/updateStatus', {dynamicId:dynamicId,status:status}, function (result) {
                if (result.status == 200) {
                    window.location.href = location.href;
                    return true;
                }else{
                    layer.msg(result.msg, {
                        icon: 0,
                        skin: 'u-msg',
                        time: 2200,
                    });
                }
            }, 'json');
    }
</script>
</html>